﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using Spire.Doc;

namespace Quality.Commons
{
    /// <summary>
    /// OfficeScanner 用于将word文档和ppt文档中的页转换为图片。
    /// </summary>
    public class OfficeScanner
    {
        public void ReadWordFile(string filePath, RichTextBox rtb)
        {
            Document document = new Document();
            document.LoadFromFile(filePath);
            var tmpfile = Commons.Paths.ApplicationTempResources + "\\" + Path.GetFileName(filePath) + DateTime.Now.Ticks;
            document.SaveToFile(tmpfile, FileFormat.Rtf); 
            rtb.BeginInvoke(new Action(() =>
            {
                rtb.Visible = false;
                rtb.LoadFile(tmpfile, RichTextBoxStreamType.RichText);
                rtb.SelectionStart = rtb.GetFirstCharIndexFromLine(0);
                rtb.SelectionLength = rtb.Lines[0].Length + 1;
                if (rtb.SelectedText.Contains("Spire"))
                {
                    rtb.SelectedText = String.Empty;
                }
                rtb.Visible = true;
            }));
        }
    }
}
